﻿@model IEnumerable<PersonalWebsite.Models.Contact>

@{
    ViewBag.Title = "Index";
}

<table class="layui-table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.ContactName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.EMail)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Details)
            </th>
            <th></th>
        </tr>
    </thead>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ContactName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.EMail)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Details)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ContactID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ContactID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ContactID })
        </td>
    </tr>
}

</table>

<script>
    function getTdValue() {
        var tableID = document.getElementsByClassName("layui-table")[0];
        for (var i = 1; i < tableID.rows.length; i++) {
            // 若Details长度大于32个字符，则截取前32个字符显示
            var str = tableID.rows[i].cells[2].innerHTML.trim();
            if (str.length > 32) {
                tableID.rows[i].cells[2].innerHTML = str.substring(0, 32) + "......";
            }
        }
    }

    getTdValue();
</script>
